#include <kew/kew.h>

/* At the moment, we're assuming there is no need for the component to have subcomponents */

struct _KewComponentObject {
    KewObject super;
    
    KewContainerObject *container;
    gpointer activation_cache;

    KewStringObject *mime_type;
    KewDataObject *data;
};

KewComponentObject *kew_component_new(KewContainerObject *container, KewStringObject *mime_type, KewDataObject *data)
{
    KewComponentObject *result = kew_alloc(KewComponentType);
    kew_object_init(result);
    result->container = container;
    result->activation_cache = NULL;
    result->mime_type = mime_type;
    result->data = data;    
}

KEW_METHOD(Component_in) /* :Container */
{
    KewComponentObject *container = kew_type_check(args[0], &kew_container_type);
    results[0] = kew_component_new(container, imp->mime_type, imp->data);
}

KEW_METHOD(Component_data)
{
    results[0] = imp->data;
}

KEW_METHOD(Component_type)
{
    results[0] = imp->type;
}

KEW_METHOD(Component_activate) /* :Args... ^Results... */
{
    kew_container_activate(imp->container, imp->type, imp->data, args[0], results[0]);
}

/* FIXME: get this into a KewPrimitiveFactoryObject (not to be confused with a KewBlockBasedFactoryObject) */

KEW_METHOD(ComponentFactory_new)
{
    KewComponentObject *container = kew_type_check(args[0], &kew_container_type);
    KewStringObject *mime_type = kew_type_check(args[1], &kew_string_type);
    KewDataObject *data = kew_type_check(args[2], &kew_data_type);
    results[0] = kew_component_new(container, mime_type, data);
}